package easymusic.baseutility;

import com.easymusic.EasyMusicMainActivity;
import easymusic.baseinterface.*;
import com.easymusic.R;

import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.app.Notification.Builder;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

@SuppressLint("NewApi")
public class EasyMusicAppService extends Service{
	public class EasyMusicAppServiceBinder extends Binder{
		public IBasicService getService(){
			return EasyMusicAppService.this.m_service;
		}
	}
	
	public final static int FOREGROUD_NOTIFICATION_ID = 1;
	private IBasicService m_service;
	private EasyMusicAppServiceBinder m_binder = new EasyMusicAppServiceBinder();

	@Override
	public IBinder onBind(Intent intent) {
		return m_binder;
	}
	
	@Override 
	public void onCreate(){
		m_service = AbstractService.getServiceManager();
		m_service.startService(this, getApplicationContext());
		
		Builder builder = new Notification.Builder(getBaseContext());
		builder.setContentText(getText(R.string.app_name));
		builder.setContentTitle(getText(R.string.app_name));
		builder.setSmallIcon(R.drawable.easy_music_icon);
		Intent intent = new Intent(getApplicationContext(), EasyMusicMainActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
		PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
		builder.setContentIntent(pendingIntent);
		
		//Bitmap map = BitmapFactory.decodeResource(getResources(), R.drawable.easy_music_icon);
		//builder.setLargeIcon(map);
		Notification note = builder.getNotification();

	    startForeground(FOREGROUD_NOTIFICATION_ID, note);
	}
}
